package very.util.format

import java.util.regex.Pattern

object SimpleTextFormatter {
  // 注意没有
  private val reg = Pattern.compile("\\{([a-zA-Z0-9_-]+)\\}")
  def processTemplate(template: String, data: Map[String, String]): String = {
    val sb = new StringBuffer
    val m = reg.matcher(template)
    while (m.find) {
      val value = data.getOrElse(m.group(1), "")
      m.appendReplacement(sb, value)
    }
    m.appendTail(sb)
    sb.toString
  }
}
